#include <bits/stdc++.h>
using namespace std;

bool check(int zeros, int ones, int halfk) {
  return (zeros >= halfk && ones >= halfk);
}

bool solve(int n, int k, char *s) {
  for (int i = k; i < n; ++i) {
    if (s[i] == '?' || s[i] == s[i % k]) {
      continue;
    }
    if (s[i % k] == '?') {
      s[i % k] = s[i];
    } else {
      return false;
    }
  }
  int ones = 0, zeros = 0;
  for (int i = 0; i < k; ++i) {
    if (s[i] == '0')
      ones++;
    else if (s[i] == '1')
      zeros++;
  }
  return (ones <= k / 2 && zeros <= k / 2);
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int n, k;
    cin >> n >> k;
    char s[n + 1];
    cin >> s;
    cout << (solve(n, k, s) ? "YES\n" : "NO\n");
  }
}
